package com.example.mvc.controller;

import com.example.mvc.bean.BookType;
import com.example.mvc.bean.User;
import com.example.mvc.service.BookService;
import com.example.mvc.service.UserService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/updateBookTypeServlet")
public class UpdateBookTypeServlet extends HttpServlet {
 BookService bookService = new BookService();
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
        String tid = request.getParameter("tid");
        String name = request.getParameter("name");
        BookType bookType = new BookType();
        bookType.setTid(Integer.parseInt(tid));
        bookType.setName(name);
        bookService.updateBookType(bookType);
        String contextPath = request.getContextPath();
        resp.sendRedirect(contextPath+"/bookTypeList");

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }
}
